// https://nuxt.com/docs/api/configuration/nuxt-config
import { fileURLToPath } from 'node:url';

export default defineNuxtConfig({
  compatibilityDate: '2025-07-15',
  devtools: { enabled: true },
  nitro: {
    logLevel: process.env.NODE_ENV === 'development' ? 1 : 3,
    compressPublicAssets: true,
    minify: true,
  },
  modules: [
    '@nuxt/icon',
    '@nuxt/image',
    '@vant/nuxt',
    '@pinia/nuxt',
    '@vueuse/nuxt'
  ],
  vant: {},
  ssr: true,
  pinia: {
    storesDirs: ['./app/stores/**']
  },
  css: [
    '~/assets/css/global.css',
    '~/assets/scss/main.scss',
    'vant/lib/index.css'
  ],
  vite: {
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@use "@/assets/scss/mixins" as *;`
        }
      }
    },
    build: {
      minify: 'terser',
      terserOptions: {
        compress: {
          pure_funcs: process.env.NODE_ENV === 'production' ? ['console.log'] : []
        }
      }
    },
    plugins: process.env.ANALYZE ? [
      {
        ...require('rollup-plugin-visualizer').visualizer({
          filename: 'dist/stats.html',
          open: true,
          gzipSize: true
        }),
        apply: 'build'
      }
    ] : []
  },
  experimental: {
    viewTransition: true,
    payloadExtraction: false,
  },
  image: {
    formats: ['webp', 'avif', 'png', 'jpg'],
    quality: 80,
    densities: [1, 2],
    screens: {
      xs: 320,
      sm: 640,
      md: 768,
      lg: 1024,
      xl: 1280,
      xxl: 1536,
    },
    presets: {
      avatar: {
        modifiers: {
          format: 'webp',
          width: 50,
          height: 50,
          quality: 80
        }
      },
      cover: {
        modifiers: {
          format: 'webp',
          width: 300,
          height: 200,
          quality: 85
        }
      }
    },
    provider: 'ipx',
    ipx: {
      maxAge: 60 * 60 * 24 * 365
    }
  },
  
  alias: {
    '~': fileURLToPath(new URL('./app', import.meta.url)),
    '@': fileURLToPath(new URL('./app', import.meta.url)),
    '~~': fileURLToPath(new URL('./', import.meta.url)),
    '@@': fileURLToPath(new URL('./', import.meta.url)),
  },
  app: {
    baseURL: process.env.NODE_ENV === 'production' ? '/cike/' : '/',
    pageTransition: false,
    layoutTransition: false,
    head: {
      viewport: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, viewport-fit=cover',
      meta: [
        { name: 'format-detection', content: 'telephone=no' },
        { name: 'theme-color', content: '#0f0f23' }
      ],
    },
  },
  
  
  // PostCSS 配置 - px 转 vw
  postcss: {
    plugins: {
      'postcss-px-to-viewport-8-plugin': {
        viewportWidth: 750,
        unitPrecision: 3,
        viewportUnit: 'vw',
        selectorBlackList: ['.ignore', '.hairlines', 'van-'],
        minPixelValue: 1,
        mediaQuery: false,
        exclude: [/node_modules/],
        include: [/app/],
        landscape: false,
        landscapeUnit: 'vw',
        landscapeWidth: 568
      }
    }
  },
  typescript: {
    typeCheck: false,
  },
  build: {
    analyze: process.env.ANALYZE === 'true'
  }
});